/**
 * routes
 */
const routes = [
  {
    name: "home",
  },
  {
    name: "banner",
    children: [
      {
        name: "banner-list",
      },
      { name: "banner-add" },
    ],
  },
  {
    name: "manager",
    children: [
      {
        name: "manager-list",
      },
    ],
  },
  {
    name: "test",
    children: [{ name: "test-1" }, { name: "test-2" }],
  },
];

const roles = ["banner-list", "banner"];

/**
 * 根据 name 获取 这个 name 在 routes 数组中的 children 字段。
 * @param {*} routes
 * @param {*} name
 */
function getChildrenByName(routes, name) {
  let result = [];
  for (let i = 0; i < routes.length; i++) {
    const route = routes[i];
    if (route.name === name) {
      result = route.children ? route.children.map((a) => a.name) : [];
      break;
    }

    if (route.children) {
      result = getChildrenByName(route.children, name);
    }
  }
  return result;
}

const arr = roles.filter((role) => {
  const children = getChildrenByName(routes, role);
  return !children.length;
});

console.log(arr);
